package thread.homework.problem1method2;

public class Print {
    private boolean flag = false;

    public synchronized void printNum(int i) {
        if (flag) {
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.print(i);
        flag = true;
        this.notifyAll();
    }

    public synchronized void printChar(char c) {
        if (!flag) {
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(c);
        flag = false;
        this.notifyAll();
    }
}
